package com.example.idachuappone.index.adapter;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.example.idachuappone.R;
import com.example.idachuappone.index.entity.FamilyFeastRecipes;

public class AdapterHotGreedName extends BaseAdapter {
	private Context context;
	private List<String[]> listmap;

	private class ViewHolder {
		private TextView tv1;
		private TextView tv2;

		private ViewHolder() {
		}
	}

	public AdapterHotGreedName(Context context) {
		this.context = context;
	}

	public void setList(List<FamilyFeastRecipes> list) {
		List<String[]> temp = new ArrayList();
		int i = 0;
		while (i < list.size()) {
			String[] str = new String[] { "", "" };
			str[0] = list.get(i).getName();
			i++;
			if (i < list.size()) {
				str[1] = list.get(i).getName();
			}
			temp.add(str);
			i++;
		}
		this.listmap = temp;
	}

	@Override
	public int getCount() {
		return this.listmap == null ? 0 : this.listmap.size();
	}

	@Override
	public Object getItem(int position) {
		return this.listmap == null ? null : (String[]) this.listmap.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder;
		if (convertView == null) {
			holder = new ViewHolder();
			convertView = LinearLayout.inflate(this.context, R.layout.simple_hot_service_greed_item, null);
			holder.tv1 = (TextView) convertView.findViewById(R.id.tv1);
			holder.tv2 = (TextView) convertView.findViewById(R.id.tv2);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		String[] str = this.listmap.get(position);
		holder.tv1.setText(str[0]);
		holder.tv2.setText(str[1]);
		return convertView;
	}
}
